import { createStore } from 'vuex'
import user from './modules/news'
import news from './modules/news'

//参见vuex官方文档 https://vuex.vuejs.org/zh/guide/structure.html
export default createStore({
	//状态子模块，避免单文件状态数据太臃肿
	modules: {
		user,
		//新闻子状态，参见./modules/news.js文件
		news
	},
	state: {
		count: 10
	},
	mutations: {
		increment(state, value) {
			state.count += value;
		},
		decrement(state, value) {
			state.count -= value;
		}
	},
	getters: {
		count2: state => state.count * 2
	},
	actions: {
		incrementAsync({ commit }, value) {
			setTimeout(() => commit('increment', value), 2000);
		}
	}
})
